package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.rc.dto.ShspPageDto;
import org.rc.entity.Shsp;
import org.rc.mapper.ShspMapper;
import org.rc.service.ShspService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ShspServiceImpl extends ServiceImpl<ShspMapper, Shsp> implements ShspService {
    @Override
    public void addShsp(Shsp shsp) {
        this.save(shsp);
    }

    @Override
    public Page<Shsp> getShspPage(ShspPageDto shspPageDto) {
        Page<Shsp> page = new Page<>(shspPageDto.getPageNo(),shspPageDto.getPageSize());
        QueryWrapper<Shsp> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(shspPageDto.getName()),"name",shspPageDto.getName());
        return this.baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public void updateShsp(Shsp shsp) {
        this.updateById(shsp);
    }

    @Override
    public void deleteShsp(Long id) {
        this.removeById(id);
    }

    @Override
    public void batchDeleteShsp(List<Long> ids) {
        this.removeByIds(ids);
    }

    @Override
    public List<Shsp> getAllShsps() {
        return list();
    }

    @Override
    public Shsp getByShspId(Long id) {
        return this.getById(id);
    }

    @Override
    public List<Shsp> getShspsByIds(List<Long> ids) {
        QueryWrapper<Shsp> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",ids);
        return list(queryWrapper);
    }
}
